﻿@using FunArts.EasyDevOps.Shared.Models.Enums
@inherits LayoutComponentBase

<MApp>
    @* <MSystemBar App> *@
    @*     <MSpacer></MSpacer> *@

    @*     <MIcon>mdi-square</MIcon> *@

    @*     <MIcon>mdi-circle</MIcon> *@

    @*     <MIcon>mdi-triangle</MIcon> *@
    @* </MSystemBar> *@

    <MNavigationDrawer @bind-Value="_drawer"
                       App>
        <MSheet Color="grey lighten-4"
                Class="pa-1">
            <MExpansionPanels>
                <MExpansionPanel>
                    <MExpansionPanelHeader Color="@(SshClientService.IsConnected?"teal accent-2":"deep-purple lighten-4")">
                        <MCardTitle Style="font-size: large">
                            @(SshClientService.IsConnected ? "已连接服务器" : "连接到服务器")
                        </MCardTitle>
                    </MExpansionPanelHeader>
                    <MExpansionPanelContent>
                        <MForm Model="_connectInfoViewModel"
                               ValidateOn="_validateOn"
                               AutoLabel>
                            <MSelect TItem="SystemTypeEnum"
                                     TItemValue="SystemTypeEnum"
                                     TValue="SystemTypeEnum"
                                     Label="系统类型"
                                     Items="_systemTypeEnumList"
                                     ItemText="item => item.ToString()"
                                     ItemValue="item => item"
                                     @bind-Value="_connectInfoViewModel.SystemType">
                            </MSelect>
                            <MTextField @bind-Value="_connectInfoViewModel.Host"
                                        Label="连接地址">
                            </MTextField>
                            <MTextField @bind-Value="_connectInfoViewModel.User"
                                        Label="用户名">
                            </MTextField>
                            <MTextField Type="@(_isPasswordVisible ? " text" :"password")"
                                        @bind-Value="_connectInfoViewModel.Pwd"
                                        AppendIcon="@(_isPasswordVisible ? "mdi-eye-off" : "mdi-eye")"
                                        OnAppendClick="TogglePasswordVisibility"
                                        Clearable
                                        Label="密码">
                            </MTextField>
                            @if (SshClientService.IsConnected)
                            {
                                <MButton Type="submit" Block Color="lime" OnClick="CloseConnect">断开连接</MButton>
                            }
                            else
                            {
                                <MButton Type="submit" Block Color="primary" Loading="IsConnecting" Disabled="IsConnecting" OnClick="ConnectService">连接</MButton>
                            }
                            @if (!string.IsNullOrWhiteSpace(ConnectErrorMsg))
                            {
                                <MCardText Class="red--text">@ConnectErrorMsg</MCardText>
                            }
                        </MForm>
                    </MExpansionPanelContent>

                </MExpansionPanel>
            </MExpansionPanels>

        </MSheet>

        <MDivider></MDivider>

        <MList>
            @foreach (var item in _navItems)
            {
                if (item.Children?.Any() is true)
                {
                    <MListGroup NoAction Group="@item.Group">
                        <ActivatorContent>
                            <MListItemIcon>
                                <MIcon>@item.Icon</MIcon>
                            </MListItemIcon>
                            <MListItemContent>
                                <MListItemTitle>@item.Name</MListItemTitle>
                            </MListItemContent>
                        </ActivatorContent>
                        <ChildContent>
                            @foreach (var subNavItem in item.Children)
                            {
                                <MListItem Link Href="@subNavItem.Url">
                                    <MListItemIcon>
                                        <MIcon>@subNavItem.Icon</MIcon>
                                    </MListItemIcon>

                                    <MListItemContent>
                                        <MListItemTitle>@subNavItem.Name</MListItemTitle>
                                    </MListItemContent>
                                </MListItem>
                            }
                        </ChildContent>
                    </MListGroup>
                }
                else
                {
                    <MListItem Link Href="@item.Url">
                        <MListItemIcon>
                            <MIcon>@item.Icon</MIcon>
                        </MListItemIcon>

                        <MListItemContent>
                            <MListItemTitle>@item.Name</MListItemTitle>
                        </MListItemContent>
                    </MListItem>
                }
            }
        </MList>
    </MNavigationDrawer>

    <MMain>
        <MContainer Fluid>
            <MErrorHandler>
                @Body
            </MErrorHandler>
        </MContainer>
    </MMain>
</MApp>

<style>
    .disconnected-title {
        font-size: 1.2rem;
        background-color: #CE93D8;
    }

    .connected-title {
        font-size: 1.5rem;
        background-color: #A7FFEB;
    }
</style>